package com.wmx.producer;

import org.apache.kafka.common.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class KafkaController {
    @Autowired
    KafkaTemplate kafkaTemplate;


    /* ###########################kafka 测试类###########################*/
    @RequestMapping("/testKafka")
    @ResponseBody
    public void testkafka() {
        String message = "{\"transNo\":\"kafka23456789\",\"idLogDs\":\"idLogDsretyuio\"}";
        try {

            ListenableFuture send = kafkaTemplate.send("wumengxin", "hi", message);
            System.out.println("ok");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.toString());
        }
    }

}
